package com.atguigu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class MyRedissonConfig {

    /**
     * 所有对redisson的使用都是通过RedissonClient对象
     * @return
     * @throws IOException
     */
    @Value("${spring.redis.password}")
    private String password;
    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson() throws IOException {


        // 1. 创建配置
        Config config = new Config();
        // redis:// or rediss:// (for SSL connection)
        config.useSingleServer().setAddress("redis://121.4.160.200:6379").setPassword(password);
        // 2. 根据Config对象创建出RedissonClient实例
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
